package com.lmt.ymcc.mq.consumer;


import com.alibaba.fastjson.JSONObject;
import com.lmt.ymcc.dto.AliPayMessageDto;
import com.lmt.ymcc.service.ICourseOrderService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup="alipay-course-order-consumer",
        topic="paynofity-topic",
        selectorExpression="alipay-tags",
        messageModel= MessageModel.BROADCASTING
)
public class OrderAliPayConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private ICourseOrderService courseOrderService;


    @Override
    public void onMessage(MessageExt messageExt) {
        String message = new String(messageExt.getBody(), StandardCharsets.UTF_8);
        AliPayMessageDto dto = JSONObject.parseObject(message, AliPayMessageDto.class);
        courseOrderService.updateOrderByPayNotify(dto);
    }
}